﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;

public partial class ucControl_ucDangkylaithu : System.Web.UI.UserControl
{
    TblMenuParrentDAO menuPaDAO = new TblMenuParrentDAO(Global.CONNECTION_STRING);
    TblMenuChildDAO menuChildDAO = new TblMenuChildDAO(Global.CONNECTION_STRING);
    TblItemsDAO itemDAO = new TblItemsDAO(Global.CONNECTION_STRING);
    TblNoiDungLaiXeThuDAO ndDAO = new TblNoiDungLaiXeThuDAO(Global.CONNECTION_STRING);
    TblDKLaiThuDAO dklaixeDAO = new TblDKLaiThuDAO(Global.CONNECTION_STRING);


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadMenuPa();
            LoadItemLeft();
            
            //string id = Request.QueryString["id"];
            //if (id != "" || id != null)
            //{
            //    LoadLuaChon1();
            //}
            LoadLuaChon1();
            LoadLuaChon2();
            LoadLuaChon3();
        }
    }
  
    private void LoadItemLeft()
    {
        rpItemLEft.DataSource = itemDAO.GetItem_New();
        rpItemLEft.DataBind();
    }

    private void LoadMenuPa()
    {
        rpMenuPa.DataSource = menuPaDAO.GetAll();
        rpMenuPa.DataBind();
    }

   
    protected void rpMenuPa_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater reChildMenuLeft = (Repeater)e.Item.FindControl("rpmenuChild");
            HiddenField hidIDMenuPLeft = (HiddenField)e.Item.FindControl("hid");
            hidIDMenuPLeft.Value = DataBinder.Eval(e.Item.DataItem, "IDMenuParent").ToString();

            string id = hidIDMenuPLeft.Value;
            if (reChildMenuLeft != null)
            {
                reChildMenuLeft.DataSource = menuChildDAO.GetCateChild_ByIDParrent(Global.ConvertToInt(id));
                reChildMenuLeft.DataBind();
            }
        }
    }
    protected void btnGui_Click(object sender, EventArgs e)
    {
        bool flag = false;
        try
        {
            TblDKLaiXe dklaixe = new TblDKLaiXe();
            dklaixe.FulName = txtFullName.Text.Trim();
            dklaixe.Address = txtAddress.Text;
            dklaixe.LoaiXeMuonLaiThu = txtLoaiXeMuonLaiThu.Text;
            dklaixe.SoBangLaiXeOto = txtBangLai.Text;
            dklaixe.PhoneMobile = txtPhone.Text;
            dklaixe.NgayDK = Convert.ToDateTime(txtDateTime.Text.ToString());
            dklaixe.Hour = Convert.ToInt32(drGio.Text);      
            dklaixe.Time = txtDateTime.Text + " " + drGio.SelectedItem.Text + ":" + drPhut.SelectedItem.Text + ":" + drAM_PM.SelectedItem.Text;

            dklaixeDAO.DKLaiThu_InsUp(dklaixe, 1);

            flag = true;  
 

        }
        catch (Exception ex)
        {
            throw ex;
        }
        if (flag)
        {
            txtAddress.Text = txtBangLai.Text = txtLoaiXeMuonLaiThu.Text = txtFullName.Text = txtPhone.Text = txtDateTime.Text = string.Empty;
            lbMessage.Text = "Bạn đã đăng ký thành công!";
        }
    }

    private void LoadLuaChon1()
    {
        //string id = Request.QueryString["id"];
        form1.DataSource = ndDAO.GetNoiDung_ByID(1);
        form1.DataBind();
    }
    private void LoadLuaChon2()
    {
        //string id = Request.QueryString["id"];
        form2.DataSource = ndDAO.GetNoiDung_ByID(2);
        form2.DataBind();
    }
    private void LoadLuaChon3()
    {
        //string id = Request.QueryString["id"];
        form3.DataSource = ndDAO.GetNoiDung_ByID(3);
        form3.DataBind();
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        txtAddress.Text = txtBangLai.Text = txtLoaiXeMuonLaiThu.Text = txtFullName.Text = txtPhone.Text = string.Empty;
    }
}
